All Packages Class Hierarchy This Package Previous Next Index
Class sun.servlet.http.MimeHeaders
java.lang.Object
|
+----sun.servlet.http.MimeHeaders
- public class MimeHeaders
- extends Object
This class is used to contain standard internet message headers,
used for SMTP (RFC822) and HTTP (RFC2068) messages as well as for
MIME (RFC 2045) applications such as transferring typed data and
grouping related items in multipart message bodies.
Message headers, as specified in RFC822, include a field name
and a field body. Order has no semantic significance, and several
fields with the same name may exist. However, most fields do not
(and should not) exist more than once in a header.
Many kinds of field body must conform to a specified syntax,
including the standard parenthesized comment syntax. This class
supports only two simple syntaxes, for dates and integers.
When processing headers, care must be taken to handle the case of
multiple same-name fields correctly. The values of such fields are
only available as strings. They may be accessed by index (treating
the header as an array of fields), or by name (returning an array
of string values).
-
MimeHeaders()
- Creates a new MimeHeaders object using a default buffer size.
-
MimeHeaders(int)
- Creates a new MimeHeaders object using the specified buffer size.
-
clear()
- Clears all header fields.
-
containsHeader(String)
- Returns true if the specified field is contained in the header,
otherwise returns false.
-
dump(PrintStream)
- Dumps current headers to specified PrintStream for debugging.
-
find(String)
- Finds and returns a header field with the given name.
-
getAll(byte[], int)
-
Get the current header fields in the byte array buf.
-
getDateHeader(String)
- Returns the date value of a header with the specified name.
-
getField(int)
- Returns the Nth header field, or null if there is no such header.
-
getFieldCount(String)
- Returns the number of fields using a given field name.
-
getHeader(int)
- Returns the body of the nth header field where n >= 0.
-
getHeader(String)
- Returns the string value of one of the headers with the
specified name.
-
getHeaderName(int)
- Returns the name of the nth header field where n >= 0.
-
getHeaders(String)
- Returns the string value of all of the headers with the
specified name.
-
getIntHeader(String)
- Returns the integer value of a header with the specified name.
-
names()
- Returns an enumeration of strings representing the header field names.
-
putDateHeader(String)
- Creates a new header field whose value is the current date and time.
-
putDateHeader(String, long)
- Creates a new header field whose value is the specified time.
-
putHeader()
- Adds a partially constructed field to the header.
-
putHeader(String)
- Finds a header field given name.
-
putHeader(String, String)
- Creates a new header field whose value is the specified string.
-
putIntHeader(String, int)
- Creates a new header field whose value is the specified integer.
-
read(ServletInputStream)
- Reads header fields from the specified servlet input stream until
a blank line is encountered.
-
removeHeader(String)
- Removes a header field with the specified name.
-
size()
- Returns the current number of header fields.
-
toString()
- Returns a lengthly string representation of the current header fields.
-
write(ServletOutputStream)
- Writes out header fields to the specified servlet output stream.
MimeHeaders
public MimeHeaders(int len)
- Creates a new MimeHeaders object using the specified buffer size.
- Parameters:
- len - the buffer size initially used for parsing headers
MimeHeaders
public MimeHeaders()
- Creates a new MimeHeaders object using a default buffer size.
clear
public void clear()
- Clears all header fields.
size
public int size()
- Returns the current number of header fields.
names
public Enumeration names()
- Returns an enumeration of strings representing the header field names.
Field names may appear multiple times in this enumeration, indicating
that multiple fields with that name exist in this header.
putHeader
public void putHeader(String name,
String s)
- Creates a new header field whose value is the specified string.
- Parameters:
- name - the header name
- s - the header field string value
putIntHeader
public void putIntHeader(String name,
int i)
- Creates a new header field whose value is the specified integer.
- Parameters:
- name - the header name
- i - the header field integer value
putDateHeader
public void putDateHeader(String name,
long t)
- Creates a new header field whose value is the specified time.
The encoding uses RFC 822 date format, as updated by RFC 1123.
- Parameters:
- name - the header name
- t - the time in number of milliseconds since the epoch
putDateHeader
public void putDateHeader(String name)
- Creates a new header field whose value is the current date and time.
- Parameters:
- name - the header name
getHeader
public String getHeader(String name)
- Returns the string value of one of the headers with the
specified name.
- Parameters:
- name - the header field name
- Returns:
- the string value of the field, or null if none found
- See Also:
- getHeaders
getHeaders
public String[] getHeaders(String name)
- Returns the string value of all of the headers with the
specified name.
- Parameters:
- name - the header field name
- Returns:
- array values of the fields, or null if none found
- See Also:
- getHeader
getIntHeader
public int getIntHeader(String name) throws NumberFormatException
- Returns the integer value of a header with the specified name.
- Parameters:
- name - the header field name
- Returns:
- the integer value of the header field, or -1 if the header
was not found
- Throws: NumberFormatException
- if the integer format was invalid
getDateHeader
public long getDateHeader(String name) throws IllegalArgumentException
- Returns the date value of a header with the specified name.
- Parameters:
- name - the header field name
- Returns:
- the date value of the header field in number of milliseconds
since the epoch, or -1 if the header was not found
- Throws: IllegalArgumentException
- if the date format was invalid
getHeaderName
public String getHeaderName(int n)
- Returns the name of the nth header field where n >= 0. Returns null
if there were fewer than (n + 1) fields. This can be used to iterate
through all the fields in the header.
getHeader
public String getHeader(int n)
- Returns the body of the nth header field where n >= 0. Returns null
if there were fewer than (n + 1) fields. This can be used along
with getHeaderName to iterate through all the fields in the header.
getField
protected MimeHeaderField getField(int n)
- Returns the Nth header field, or null if there is no such header.
This may be used to iterate through all header fields.
getFieldCount
public int getFieldCount(String name)
- Returns the number of fields using a given field name.
find
protected MimeHeaderField find(String name)
- Finds and returns a header field with the given name. If no such
field exists, null is returned. If more than one such field is
in the header, an arbitrary one is returned.
removeHeader
public void removeHeader(String name)
- Removes a header field with the specified name. Does nothing
if such a field could not be found.
- Parameters:
- name - the name of the header field to be removed
containsHeader
public boolean containsHeader(String name)
- Returns true if the specified field is contained in the header,
otherwise returns false.
- Parameters:
- name - the field name
read
public void read(ServletInputStream in) throws IOException
- Reads header fields from the specified servlet input stream until
a blank line is encountered.
- Parameters:
- in - the servlet input stream
- Throws: IllegalArgumentException
- if the header format was invalid
- Throws: IOException
- if an I/O error has occurred
write
public void write(ServletOutputStream out) throws IOException
- Writes out header fields to the specified servlet output stream.
- Parameters:
- out - the servlet output stream
- Throws: IOException
- if an I/O error has occurred
putHeader
protected MimeHeaderField putHeader(String name)
- Finds a header field given name. If the header doesn't exist,
it will create a new one.
- Parameters:
- name - the header field name
- Returns:
- the new field
putHeader
protected MimeHeaderField putHeader()
- Adds a partially constructed field to the header. This
field has not had its name or value initialized.
getAll
public int getAll(byte buf[],
int buf_offset)
- Get the current header fields in the byte array buf. The headers
fields are placed starting at offset buf_offset.
- Returns:
- the number of bytes written into buf.
toString
public String toString()
- Returns a lengthly string representation of the current header fields.
- Overrides:
- toString in class Object
dump
public void dump(PrintStream out)
- Dumps current headers to specified PrintStream for debugging.
All Packages Class Hierarchy This Package Previous Next Index